import 'package:flutter/material.dart';
import 'Load.dart';
import 'bean/datedetails.dart';
import 'servicepath.dart';

class Detailspage extends StatefulWidget {
  final arguments;
  Detailspage({Key? key, this.arguments}) : super(key: key);

  @override
  _DetailspageState createState() => _DetailspageState(arguments);
}

class _DetailspageState extends State<Detailspage> {
  final arguments;
  _DetailspageState(this.arguments);

  Data? _data;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    var jsondata = {"id": arguments["id"], "token": "qlVquQZPYSeaCi6u"};
    getDatedetailsinfo(jsondata);
  }

  //获取日志详细信息
  void getDatedetailsinfo(var jsondata) {
    getDateInfodetails(jsondata).then((value) {
      Datedetails? datedetails = value;
      setState(() {
        if (datedetails != null) {
          String msg = datedetails!.msg!;
          int code = datedetails!.code!;
          print("code-- >" + code.toString());
          print("msg-- >" + msg);
          if (code == 200) {
            _data = datedetails.data!;
          }
        }
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text("详情页面"),
        ),
        body: _data == null ? LoadPage() : _details());
  }

  Widget? _details() {
    return Container(
      padding: const EdgeInsets.only(left: 20, right: 20),
      child: Scrollbar(
        thickness: 2.0, //滑动条的高度
        interactive: true, //滑动条为true 可拖动
        thumbVisibility: true, //一直显示滑动条
        child: SingleChildScrollView(
          scrollDirection: Axis.vertical,
          primary: true,
          physics: const BouncingScrollPhysics(),
          child: Column(
            children: [
              Text(_data!.title != null ? _data!.title! : "test",
                  style: const TextStyle(
                      fontSize: 18, fontWeight: FontWeight.bold)),
              GestureDetector(
                onTap: () {
                  //导航到新路由
                  Navigator.push(
                    context,
                    MaterialPageRoute(builder: (context) {
                      return LoadPage();
                    }),
                  );
                },
                child: Text(
                  "日期${_data!.date!}",
                  style: const TextStyle(
                    fontSize: 12,
                  ),
                ),
              ),
              Text(_data!.content!,
                  style: const TextStyle(
                    fontSize: 16,
                  ))
            ],
          ),
        ),
      ),
    );
  }
}
